<?php

declare(strict_types=1);
namespace Service\AppService;

use Service\BaseService;
use App\Service\HttpServer\HttpCurl;
use App\Service\AppService\SystemCacheConfigService;

/**
 * 异常通知
 * @author chenshubo
 */
class MonitorService extends BaseService
{
    protected $url = 'https://oapi.dingtalk.com/robot/send?access_token=a5b926757c9ef342ce183e9abeb6a001fe2e5c5fe56f2b679057d11c2182d28f';
    /**
     * 发送系统异常
     * @param string $contents
     */
    public function sendMsg(string $contents)
    {
        $config  = SystemCacheConfigService::instance()->getCacheInfoBySystemCode('sysconfig');
        $AppName = $config['AppName'] ?? '云仓系统';
        $message="【云仓异常消息提醒】【{$AppName}】{$contents}";
        $data = [
            'msgtype' => 'text',
            'text' => [
                'content' => $message
            ]
        ];
        
        HttpCurl::instance()->apiRequest($this->url,$data,'POST','json',['Content-Type: application/json;charset=utf-8']);
    }
}